package com.crane.framework.utils;

import java.text.DecimalFormat;
import java.util.Random;

public class RandomCodeGenerator {

  private static final Random random = new Random();
  private static final DecimalFormat df = new DecimalFormat();

  public static String generateRandomCode(int length) {
    if (length <= 0) {
      throw new IllegalArgumentException("长度必须大于零。");
    }

    StringBuilder code = new StringBuilder();
    for (int i = 0; i < length; i++) {
      code.append(random.nextInt(10)); // 追加随机数字（0-9）
    }
    return code.toString();
  }

  public static String generateRandomFourDigitCode() {
    return generateRandomCode(4);
  }

  public static String generateRandomSixDigitCode() {
    return generateRandomCode(6);
  }
}
